const BASE_URL = 'http://38.12.44.37:5555/'
// const BASE_URL = 'http://127.0.0.1:5000/'
import {
	useLoginStore
} from '@/stores/loginState.js'
const store = useLoginStore()
export function request(config = {}) {
	let {
		url,
		data = {},
		method = "GET",
		header = {},
	} = config
	url = BASE_URL + url
	header['Authorization'] = store.tokenInfo.token
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method,
			header,
			data,
			success: res => {
				// console.log('res', res)
				if (res.data.code === 0) {
					resolve(res.data.data)
				} else if (res.data.code === 1) {
					uni.showModal({
						title: "错误提示",
						content: res.data.msg,
						showCancel: false
					})
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: "none"
					})
					uni.switchTab({
						url: '/pages/index/index'
					})
					reject(res.data)
				}
			},
			fail: err => {
				reject(err)
			}
		})
	})
}